<?php


namespace app\admin\controller\staff;


use app\admin\model\Staff as StaffModel;
use app\admin\model\StaffChatTime;
use app\common\Common;
use app\sys\service\GateCli;
use think\facade\Env;
use think\facade\Validate;
use think\Request;

class WsLogin extends Common
{
    // 链接绑定
    public function wsBind(Request $request){
        $data = $request->param();
        $validate = Validate::make([
            "client_id|ws链接id" => "require",
            "staff_no|客服编号" => "require",
        ]);
        if (!$validate->check($data)) {
            return failedJson($validate->getError());
        }
        $stf = \app\admin\model\Staff::where("staff_no",$data["staff_no"])->find();
        $cli = new GateCli();
        $staffInfo = $request->_user;
        $st = $cli -> wsStaffBind($data["client_id"],$data["staff_no"],$stf["id"],$staffInfo["device_id"]);
        if($st){
            return failedJson($st."绑定失败");
        }
        // 列表进出
        staffModel::allocStaff($data["staff_no"],'',"af");
        return successJson("success","绑定成功");
    }
}